<?php
/**
 * 
 * 
 * @author
 * @version 
 */
class Seo_BarController extends Zend_Controller_Action {

	
	public function buttonAction(){
		//Zen_Script::add ( '/cms/res/jquery/js/jquery.js', -10,-100);
		Zen_Script::add('/cms/res/admin/js/fancybox/jquery.fancybox-1.3.4.js');
		Zen_Style::add('/cms/res/admin/js/fancybox/jquery.fancybox-1.3.4.css');
		
		if(Zend_Registry::isRegistered('cid')){
			$page_id=Zend_Registry::get('cid');
		}else{
			$url = $this->_getParam('url');
			$url=preg_replace('/\\/?\\?.*/', '', $url);
			$url=preg_replace('/\\/$/', '', $url);
			$url .= '/'; 
			$page_id = $url;
		}		
		$page_id=md5($page_id);
		
		$form=new Seo_Form_Page();
		
		
		$this->view->page_id=$page_id;
		$this->view->form=$form;
		
			
	}
	
	public function indexAction(){
		$this->_helper->layout ()->setLayout('iframe');
		$form=new Seo_Form_Page();
		$data=Zen_Settings::get('seo', 'pages');
		if(!$data){
			$data=array();
		}
		$page_id=trim($this->_getParam('page_id'));
		
		if(isset($data[$page_id])){
			$form->setDefaults($data[$page_id]);
		}
		if ($this->_request->isPost ()) {
			if ($form->isValid ( $this->_getAllParams () )) {
				$params=$form->getValues ();
				$data[$page_id]=$params;
				
				Zen_Settings::set( 'seo', 'pages', $data);
				/*
				$this->view->success=true;
				$this->view->title=$params['title'];
				$this->view->keywords=$params['title'];
				$this->view->description=$params['title'];
				*/
				$this->_helper->FlashMessenger->setNamespace ( 'messages' )->addMessage ( array ('text' => 'Изменения сохранены', 'type' => 'alert' ) );

				$this->_redirect($_SERVER['REQUEST_URI']);				
			}
			
		}
		$this->view->form = $form;
	}
	
	
	
	
	
	
}
